package com.semidata.trp.report.report;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.ibatis.session.SqlSession;

import com.semidata.trp.report.mapper.NRTReportMapper;
import com.semidata.trp.report.model.IdGroupModel;
import com.semidata.trp.report.utils.SessionUtils;

public class GetList {
	private Map<String, Map<Integer, Integer>> idList = new HashMap<>();
	private List<String> machineList = new ArrayList<>();
	private static List<IdGroupModel> idGroup =  new ArrayList<>();

	public List<String> getMachineList() {
		SqlSession session = SessionUtils.getSession();
		try {
			NRTReportMapper mapper = session.getMapper(NRTReportMapper.class);
			machineList = mapper.getMonitorServerList();
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
			session.rollback();
		} finally {
			session.close();
		}
		return this.machineList;
	}

	public Map<String, Map<Integer, Integer>> getIdList() {
		List<Map<String, Integer>> straOrg = new ArrayList<Map<String, Integer>>();
		Map<Integer, Integer> posMediaList = new HashMap<>();
		Map<Integer, Integer> mediaTypeList = new HashMap<>();
		Map<Integer, Integer> resPosList = new HashMap<>();
		Map<Integer, Integer> straOrgList = new HashMap<>();

		SqlSession session = SessionUtils.getSession();
		try {
			NRTReportMapper mapper = session.getMapper(NRTReportMapper.class);
			idGroup = mapper.getIdGroup();
			straOrg = mapper.getOrganizationByStrategy();
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
			session.rollback();
		} finally {
			session.close();
		}
		for (Map<String, Integer> straOrgIt : straOrg) {
			straOrgList.put(straOrgIt.get("id"),
					straOrgIt.get("organization_id"));
		}
		for(IdGroupModel id : idGroup){
			posMediaList.put(id.getId(), id.getMediaId());
			mediaTypeList.put(id.getId(),id.getType());
			resPosList.put(id.getId(), id.getPositionId());
		}

		//Map<String, Map<Integer, Integer>> resultMap = new HashMap<>();
		idList.put("position", resPosList);
		idList.put("media", posMediaList);
		idList.put("mediaType", mediaTypeList);
		idList.put("organization", straOrgList);
		return this.idList;
	}
	
	
	
	public static void main(String[] args) {
		

		SqlSession session = SessionUtils.getSession();
		try {
			NRTReportMapper mapper = session.getMapper(NRTReportMapper.class);
			idGroup = mapper.getIdGroup();
			session.commit();
		} catch (Exception e) {
			e.printStackTrace();
			session.rollback();
		} finally {
			session.close();
		}
	}
}
